import Vue from "vue";
import { newGuid } from "../Utils/Guid"

export class TaskItem {
  message = ""
  id = -1
  constructor(message, id = newGuid()) {
    this.id = id
    this.message = message
  }
}

export default {
  name: "workPanel",
  namespaced: true,
  state: {
    navs: new Array(),
    // currentNavIndex: null,
    tasks: []
  },
  mutations: {
    setNavs(state, navs) {
      state.navs = navs
    },
    // setCurrentNavIndex(state, index) {
    //   state.currentNavIndex = index
    // },
    setTasks(state, tasks) {
      state.tasks = tasks
    },
    addTask(state, taskItem) {
      const newItems = state.tasks.map(item => item)
      newItems.push(taskItem)
      state.tasks = newItems
    },
    removeTask(state, taskItem) {
      const newItems = state.tasks.filter(item => item.id != taskItem.id)
      state.tasks = newItems
    }
  },
  actions: {

  }
}
export const Methods = {
  setNavs(store, navs) {
    store.commit("workPanel/setNavs", navs)
  },
  setCurrentNavIndex(store, index) {
    store.commit("workPanel/setCurrentNavIndex", index)
  },
  setTasks(store, tasks) {
    store.commit("workpanel/setTasks", tasks)
  },
  addTask(store, taskItem) {
    store.commit("workPanel/addTask", taskItem)
  },
  removeTask(store, taskItem) {
    store.commit("workPanel/removeTask", taskItem)
  }
}
